package com.blackhorse.rabbitmq.controller;

import com.blackhorse.rabbitmq.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//消息生产者
@RestController
public class SendMessageController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public String sendMessage(@RequestParam String msg,
                              @RequestParam String key) {
        //发送消息
        rabbitTemplate.convertAndSend(
                RabbitMQConfig.ITEM_TOPIC_EXCHANGE, //交换机名称
                key,  //路由key
                msg  //发送的消息
        );
        return "发送消息[" + msg + "]成功！";
    }
}
